<?php
	include_once("adb.php");
	
	class households extends adb
    {
		function households(){
			adb::adb();
		}
		/**
		*query all households in the table and store the dataset in $this->result	
		*@return if successful true else false
		*/
		
		function get_all_households(){
			$query="select household_id,household_no,household_head,discription,community_id from households";
			return $this->query($query);
		}

		function get_some_households($household_no){
			$query="select * from households where household_no like '%$household_no%'";
			return $this->query($query);
		}
		
		function add_household($household_no,$household_head,$discription,$community_id){
			//write the SQL query and call $this->query()
			$query="insert into households set household_no='$household_no', household_head='$household_head', 
			discription='$discription', community_id='$community_id'";
			//print $query;
			return $this->query($query);
		}
		/**
		*updates the record identified by id 
		*/
		function update_household($household_id,$household_no,$household_head,$discription,$community_id){
				//checking if id is set
				if (!isset($_REQUEST['id']))
				{
					echo "no id";
					exit();
				}
				$hid = $_REQUEST['id'];
			//write the SQL query and call $this->query()
			$query="update households set household_id= '$household_id', household_no='$household_no', household_head='$household_head', discription='$discription',
			community_id='$community_id' where household_id = '$hid'";
			return $this->query($query);
		}

		function get_household($id) {
			$query="select * from households where household_id = $id";
			if (!$this-> query($query)) {
				return false;
			}
			return $this->fetch();
		}

        function delete_household($household_id)
        {
            $query = "delete from households where household_id='$household_id'";

            return $this -> query($query);
        }


	}
?>